package yf.mall.controller.api;

import com.yf.annotation.IgnoreAuth;
import com.yf.response.R;
import com.yf.util.WxUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import yf.mall.service.WxMsgService;

@RestController
@RequestMapping("/api/wx")
public class ApiWxMsgController {

    @Value("${WX.TOKEN}")
    private String wxToken ;

    @Autowired
    private WxMsgService wxMsgService;

    @GetMapping("/msg/handle")
    @IgnoreAuth
    public String handle(String signature,String timestamp,String nonce,String echostr){
        if(WxUtil.checkSignature(wxToken,signature,timestamp,nonce,echostr)){
            return echostr;
        }else {
            return "error";
        }
    }

    @PostMapping("/msg/handle")
    @IgnoreAuth
    public String handle(@RequestBody String body){
        wxMsgService.handle(body);
        return "";
    }




}
